package com.cisystem.web.controller.business;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.cisystem.common.annotation.Log;
import com.cisystem.common.core.controller.BaseController;
import com.cisystem.common.core.domain.AjaxResult;
import com.cisystem.common.enums.BusinessType;
import com.cisystem.system.domain.FileAssign;
import com.cisystem.system.service.IFileAssignService;
import com.cisystem.common.utils.poi.ExcelUtil;
import com.cisystem.common.core.page.TableDataInfo;

/**
 * 文件分配Controller
 *
 * @author xxx
 * @date 2024-08-06
 */
@RestController
@RequestMapping("/business/assign")
public class FileAssignController extends BaseController {
    @Autowired
    private IFileAssignService fileAssignService;

    /**
     * 查询文件分配列表
     */
    @GetMapping("/list")
    public TableDataInfo list(FileAssign fileAssign) {
        startPage();
        List<FileAssign> list = fileAssignService.selectFileAssignList(fileAssign);
        return getDataTable(list);
    }

//    /**
//     * 导出文件分配列表
//     */
//    @PreAuthorize("@ss.hasPermi('business:assign:export')")
//    @Log(title = "文件分配", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, FileAssign fileAssign) {
//        List<FileAssign> list = fileAssignService.selectFileAssignList(fileAssign);
//        ExcelUtil<FileAssign> util = new ExcelUtil<FileAssign>(FileAssign.class);
//        util.exportExcel(response, list, "文件分配数据");
//    }
//
    /**
     * 获取文件分配详细信息
     */
    @GetMapping(value = "/findByFileId/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        FileAssign fileAssign = new FileAssign();
        fileAssign.setFileId(id);
        List<FileAssign> fileAssigns = fileAssignService.selectFileAssignList(fileAssign);
        if (!CollectionUtils.isEmpty(fileAssigns)){
            return success(fileAssigns.get(0));
        }else{
            return success(null);
        }
    }
//
//    /**
//     * 新增文件分配
//     */
//    @PreAuthorize("@ss.hasPermi('business:assign:add')")
//    @Log(title = "文件分配", businessType = BusinessType.INSERT)
//    @PostMapping
//    public AjaxResult add(@RequestBody FileAssign fileAssign) {
//        return toAjax(fileAssignService.insertFileAssign(fileAssign));
//    }
//
//    /**
//     * 修改文件分配
//     */
//    @PreAuthorize("@ss.hasPermi('business:assign:edit')")
//    @Log(title = "文件分配", businessType = BusinessType.UPDATE)
//    @PutMapping
//    public AjaxResult edit(@RequestBody FileAssign fileAssign) {
//        return toAjax(fileAssignService.updateFileAssign(fileAssign));
//    }
//
//    /**
//     * 删除文件分配
//     */
//    @PreAuthorize("@ss.hasPermi('business:assign:remove')")
//    @Log(title = "文件分配", businessType = BusinessType.DELETE)
//    @DeleteMapping("/{ids}")
//    public AjaxResult remove(@PathVariable String[] ids) {
//        return toAjax(fileAssignService.deleteFileAssignByIds(ids));
//    }
}
